﻿package mvc.controller {
	import flash.display.Shape;
	import mvc.model.MouseProxy;
	import mvc.model.PalletProxy;
	import mvc.model.ToolProxy;
	import mvc.view.PainterMediator;
	import org.puremvc.as3.multicore.interfaces.INotification;
	import org.puremvc.as3.multicore.patterns.command.SimpleCommand;
	import org.puremvc.as3.multicore.patterns.observer.Notification;
    
	public class MouseMoveCommand extends SimpleCommand {
		
		override public function execute(note:INotification):void {
			var toolProxy:ToolProxy = facade.retrieveProxy(ToolProxy.NAME) as ToolProxy;
			var mouseProxy:MouseProxy = facade.retrieveProxy(MouseProxy.NAME) as MouseProxy;
			
			var color:uint = PalletProxy(facade.retrieveProxy(PalletProxy.NAME)).color;
			
			var canvas:Canvas = PainterMediator(facade.retrieveMediator(PainterMediator.NAME)).canvas;
			var newX:Number = canvas.mouseX;
			var newY:Number = canvas.mouseY;
			
			var shape:Shape = new Shape();
			shape.graphics.moveTo(mouseProxy.x, mouseProxy.y);
			switch (toolProxy.tool) {
				case ToolProxy.PEN:
					shape.graphics.lineStyle(5, color);
					break;
				case ToolProxy.ERASER:
					shape.graphics.lineStyle(50, 0xFFFFFF);
					break;
			}
			shape.graphics.lineTo(newX, newY);
			canvas.bmp.bitmapData.draw(shape);
			
			mouseProxy.x = newX;
			mouseProxy.y = newY;
		}
	}
}